//
//  NYPrivacyViewController.m
//  Nooryes
//
//  Created by bakenPro on 4/13/20.
//  Copyright © 2020 UUU9. All rights reserved.
//

#import "NYPrivacyViewController.h"

@interface NYPrivacyViewController ()<WKNavigationDelegate>
@property (weak, nonatomic) IBOutlet WKWebView *wkwebview;
@property (assign, nonatomic)BOOL isFirstLoad;

@end

@implementation NYPrivacyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.wkwebview.navigationDelegate = self;
    [self.wkwebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.onesavour.cn/static/down/ysq.html"]]];
    
}
- (IBAction)onDisagree:(id)sender {
    _closeBlock(NO);
}

- (IBAction)onAgree:(id)sender {
    [[NSUserDefaults standardUserDefaults] setObject:@"agree" forKey:@"didAgree"];
    [self dismissViewControllerAnimated:YES completion:nil];
}
//webview加载urlrequest后，这个方法决定是同意加载或者取消
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    if (!self.isFirstLoad) {
        self.isFirstLoad = YES;
        decisionHandler(WKNavigationActionPolicyAllow);
        
    } else {
        [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:[NSDictionary dictionary] completionHandler:nil];
        decisionHandler(WKNavigationActionPolicyCancel);
    }
    
}
@end
